﻿package com.wandian.view.mediator
{
	import com.greensock.TweenLite;
	import com.wandian.controller.CLZNoticeName;
	import com.wandian.controller.PrizeCommand;
	import com.wandian.data.GameData;
	import com.wandian.model.UserInfoProxy;
	import com.wandian.util.CLZButton;
	import com.wandian.util.CLZTiming;
	import com.wandian.util.StopWatch;
	import com.wandian.util.UIHelper;
	import com.wandian.view.components.ui.AddBtn;
	import com.wandian.view.components.ui.FacePanel;
	import com.wandian.view.components.ui.FriendPanel;
	import com.wandian.view.components.ui.HornPanel;
	import com.wandian.view.components.ui.NationalDayPanel;
	import com.wandian.view.components.ui.PayBagPanel;
	import com.wandian.view.components.ui.RedBagPanel;
	import com.wandian.view.components.ui.ScrollBarTxt;
	import com.wandian.view.components.ui.mingame.sgj.MaxWinPanel;
	import com.wandian.view.components.ui.mingame.zp.ZPPanel;
	
	import flash.display.Bitmap;
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.ui.Keyboard;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;

	/**
	* @author long
	* @QQ 108232706
	* @version 1.0
	*/
	public class WindowsMediator extends Mediator
	{
		private var _mcHornPanel:Sprite;
		private var _hornPanel:HornPanel;
		private var _mcFacePanel:Sprite;
		private var _facePanel:FacePanel;
		private var _mcFriendPanel:Sprite;
		private var _friendPanel:FriendPanel;
		private var _mcCanaward:Sprite;
		private var _mcMaxWinPanel:Sprite;
		private var _maxWinPanel:MaxWinPanel;
		private var _mcZPPanel:MovieClip;
		private var _zpPanel:ZPPanel;
		private var _mcPayBagPanel:Sprite;
		private var _payBag:PayBagPanel;
		private var _mcPayPanel:Sprite;
		private var _global:GameData;
		public static const NAME:String="WindowsMediator";

		public function WindowsMediator(param1:Object=null)
		{
			this._global=GameData.getInstance();
			super(NAME, param1);
			return;
		}

		override public function onRegister():void
		{
			trace("WindowsMediator");
			facade.registerCommand(CLZNoticeName.PRIZE_BAG_REWARD_REQ, PrizeCommand);
			return;
		}

		override public function listNotificationInterests():Array
		{
			return [CLZNoticeName.SHOW_HORN_PANEL, CLZNoticeName.HIDE_HORN_PANEL, CLZNoticeName.PROP_UPDATE_NUM, CLZNoticeName.SHOW_FACE_PANEL, CLZNoticeName.HIDE_FACE_PANEL, CLZNoticeName.ON_STAGE, CLZNoticeName.SHOW_BANK_PANEL_REQ, CLZNoticeName.SHOW_FRIEND_PANEL, CLZNoticeName.HIDE_FRIEND_PANEL, CLZNoticeName.SHOW_ACTIVITY_PANEL, CLZNoticeName.HIDE_ACTIVITY_PANEL, CLZNoticeName.PRIZE_BAG_REWARD_RES, CLZNoticeName.SHOW_OPEN_SGJ_PANEL, CLZNoticeName.HIDE_CLOSE_SGJ_PANEL, CLZNoticeName.SGJ_ZP_RES, CLZNoticeName.SGJ_ZP_RANK_RES, CLZNoticeName.SHOW_OPEN_ZP_PANEL, CLZNoticeName.HIDE_CLOSE_ZP_PANEL, CLZNoticeName.SHOW_PAY_BAG_PANEL, CLZNoticeName.HIDE_PAY_BAG_PANEL, CLZNoticeName.DRAW_PAY_BAG_RES, CLZNoticeName.INIT_PAY_BAG_RES, CLZNoticeName.SHOW_BUY_VIP_PANEL_TIP, CLZNoticeName.HIDE_BUY_VIP_PANEL_TIP, CLZNoticeName.SHOW_RED, CLZNoticeName.HIDE_RED, CLZNoticeName.SHOW_NATIONAL_DAY, CLZNoticeName.HIDE_NATIONAL_DAY];
		}

		override public function handleNotification(param1:INotification):void
		{
			var _loc_2:Object=null;
			var _loc_3:DisplayObject=null;
			var _loc_4:int=0;
			var _loc_5:Sprite=null;
			var _loc_6:RedBagPanel=null;
			var _loc_7:Sprite=null;
			var _loc_8:String=null;
			var _loc_9:Object=null;
			switch (param1.getName())
			{
				case CLZNoticeName.SHOW_HORN_PANEL:
				{
					if (this._mcHornPanel == null)
					{
						this._mcHornPanel=GameData.getSprite("HornPanel");
					}
					Texas.I._mcWindosView.addChildTo(this._mcHornPanel);
					Texas.I._mcWindosView.centerXY(this._mcHornPanel, 0, -25);
					this._hornPanel=new HornPanel(this._mcHornPanel);
					break;
				}
				case CLZNoticeName.HIDE_HORN_PANEL:
				{
					Texas.I._mcWindosView.removeChildTo(this._mcHornPanel);
					this._mcHornPanel=null;
					this._hornPanel=null;
					break;
				}
				case CLZNoticeName.PROP_UPDATE_NUM:
				{
					if (this._mcHornPanel != null)
					{
					}
					if (this._hornPanel != null)
					{
						this._hornPanel.updatePropNum();
					}
					break;
				}
				case CLZNoticeName.SHOW_FACE_PANEL:
				{
					if (this._mcFacePanel != null)
					{
						this.sendNotification(CLZNoticeName.HIDE_FACE_PANEL);
					}
					else
					{
						this._mcFacePanel=GameData.getSprite("FacePanel");
						Texas.I._mcWindosView.addChild(this._mcFacePanel);
						this._mcFacePanel.x=int(GameData.config["stageW"]) + this._mcFacePanel.width;
						this._mcFacePanel.y=220;
						TweenLite.to(this._mcFacePanel, 0.5, {x: 633});
						this._facePanel=new FacePanel(this._mcFacePanel);
//						var canvasMask:Sprite=new Sprite();
//						canvasMask.graphics.beginFill(0x2B2B2B);
//						canvasMask.graphics.lineStyle(1, 0);
//						canvasMask.graphics.drawRect(0, 0, 100, 100);
//						canvasMask.graphics.endFill();
//						this._mcFacePanel.addChild(canvasMask);
					}
					break;
				}
				case CLZNoticeName.HIDE_FACE_PANEL:
				{
					if (this._mcFacePanel == null)
					{
						return;
					}
					TweenLite.to(this._mcFacePanel, 0.5, {x: int(GameData.config["stageW"]) + this._mcFacePanel.width, onComplete: this.windosViewRemove, onCompleteParams: [this._mcFacePanel]});
					this._mcFacePanel=null;
					this._facePanel=null;
					break;
				}
				case CLZNoticeName.ON_STAGE:
				{
					_loc_2=param1.getBody();
					_loc_3=_loc_2.target as DisplayObject;
					trace(_loc_3.name + "-----");
					if (_loc_3.name == "face_btn")
					{
						return;
					}
					if (_loc_3.name == "btn_friend")
					{
						return;
					}
					if (!GameData.checkStageHitTest(this._mcFacePanel, _loc_2.point))
					{
						this.sendNotification(CLZNoticeName.HIDE_FACE_PANEL);
					}
					if (!GameData.checkStageHitTest(this._mcFriendPanel, _loc_2.point))
					{
						this.sendNotification(CLZNoticeName.HIDE_FRIEND_PANEL);
					}
					break;
				}
				case CLZNoticeName.SHOW_BANK_PANEL_REQ:
				{
					if (this._global.userInfo.userVo.vip == 0)
					{
					}
					if (this._global.userInfo.userVo.bankpasswd == 0)
					{
						_loc_8=GameData.tip["NOT_VIP_TIP_BANK"];
						_loc_9={okNoticeName: CLZNoticeName.ON_PAY_VIP, tip: _loc_8, tipTitle: GameData.tip["SYSTEM_TIP"], isCancel: true, okTip: "ON_PAY_VIP_NAME", cancelTip: "I_KNOW", isSendClose: false};
						this.sendNotification(CLZNoticeName.SHOW_WINDOWS_TIP, _loc_9);
						return;
					}
					this.sendNotification(CLZNoticeName.SHOW_BANK_PANEL);
					break;
				}
				case CLZNoticeName.SHOW_FRIEND_PANEL:
				{
					if (this._mcFriendPanel != null)
					{
						this.sendNotification(CLZNoticeName.HIDE_FRIEND_PANEL);
					}
					else
					{
						this._mcFriendPanel=GameData.getSprite("FriendPanel");
						Texas.I._mcWindosView.addChild(this._mcFriendPanel);
						this._mcFriendPanel.x=-this._mcFriendPanel.width - 10;
						this._mcFriendPanel.y=129;
						TweenLite.to(this._mcFriendPanel, 0.5, {x: -3});
						this._friendPanel=new FriendPanel(this._mcFriendPanel);
					}
					break;
				}
				case CLZNoticeName.HIDE_FRIEND_PANEL:
				{
					if (this._mcFriendPanel == null)
					{
						return;
					}
					TweenLite.to(this._mcFriendPanel, 0.4, {x: -this._mcFriendPanel.width - 10, onComplete: this.windosViewRemove, onCompleteParams: [this._mcFriendPanel]});
					this._mcFriendPanel=null;
					this._friendPanel=null;
					break;
				}
				case CLZNoticeName.SHOW_ACTIVITY_PANEL:
				{
					_loc_4=param1.getBody() as int;
					this.showCanawardHandler(_loc_4);
					break;
				}
				case CLZNoticeName.HIDE_ACTIVITY_PANEL:
				{
					Texas.I._mcWindosView.removeChildTo(this._mcCanaward);
					this._mcCanaward=null;
					break;
				}
				case CLZNoticeName.PRIZE_BAG_REWARD_RES:
				{
					this._global.userInfo.userVo.canaward=0;
					if (int(this._global.userInfo.userVo.icon) == 0)
					{
						this.sendNotification(CLZNoticeName.SHOW_HELP, HelpMediator.TYPE_0);
					}
					break;
				}
				case CLZNoticeName.SHOW_OPEN_SGJ_PANEL:
				{
					if (this._mcMaxWinPanel != null)
					{
						this.sendNotification(CLZNoticeName.HIDE_CLOSE_SGJ_PANEL);
					}
					else
					{
						facade.registerCommand(CLZNoticeName.SGJ_ZP_REQ, PrizeCommand);
						facade.registerCommand(CLZNoticeName.SGJ_ZP_RANK_REQ, PrizeCommand);
						this._mcMaxWinPanel=GameData.getSprite("WinMaxPanel");
						Texas.I._mcWindosView.addChildTo(this._mcMaxWinPanel);
						Texas.I._mcWindosView.centerXY(this._mcMaxWinPanel, 55, 20);
						this._maxWinPanel=new MaxWinPanel(this._mcMaxWinPanel);
					}
					break;
				}
				case CLZNoticeName.HIDE_CLOSE_SGJ_PANEL:
				{
					facade.removeCommand(CLZNoticeName.SGJ_ZP_REQ);
					facade.removeCommand(CLZNoticeName.SGJ_ZP_RANK_REQ);
					Texas.I._mcWindosView.removeChildTo(this._mcMaxWinPanel);
					this._mcMaxWinPanel=null;
					this._maxWinPanel=null;
					break;
				}
				case CLZNoticeName.SGJ_ZP_RES:
				{
					if (this._maxWinPanel != null)
					{
						this._maxWinPanel.startGame(param1.getBody() as Array);
					}
					if (this._zpPanel != null)
					{
						this._zpPanel.startGame(param1.getBody() as Array);
					}
					break;
				}
				case CLZNoticeName.SGJ_ZP_RANK_RES:
				{
					if (this._maxWinPanel != null)
					{
						this._maxWinPanel.setRank(param1.getBody() as Array);
					}
					break;
				}
				case CLZNoticeName.SHOW_OPEN_ZP_PANEL:
				{
					if (this._mcZPPanel != null)
					{
						this.sendNotification(CLZNoticeName.HIDE_CLOSE_SGJ_PANEL);
					}
					else
					{
						facade.registerCommand(CLZNoticeName.SGJ_ZP_REQ, PrizeCommand);
						this._mcZPPanel=GameData.getMovieClip("ZPPanel");
						Texas.I._mcWindosView.addChildTo(this._mcZPPanel);
						Texas.I._mcWindosView.centerXY(this._mcZPPanel, 0, -40);
						this._zpPanel=new ZPPanel(this._mcZPPanel);
					}
					break;
				}
				case CLZNoticeName.HIDE_CLOSE_ZP_PANEL:
				{
					facade.removeCommand(CLZNoticeName.SGJ_ZP_REQ);
					Texas.I._mcWindosView.removeChildTo(this._mcZPPanel);
					this._mcZPPanel=null;
					this._zpPanel=null;
					break;
				}
				case CLZNoticeName.SHOW_PAY_BAG_PANEL:
				{
					facade.registerCommand(CLZNoticeName.INIT_PAY_BAG_REQ, PrizeCommand);
					this.sendNotification(CLZNoticeName.INIT_PAY_BAG_REQ);
					break;
				}
				case CLZNoticeName.HIDE_PAY_BAG_PANEL:
				{
					facade.removeCommand(CLZNoticeName.DRAW_PAY_BAG_REQ);
					Texas.I._mcWindosView.removeChildTo(this._mcPayBagPanel);
					this._mcPayBagPanel=null;
					this._payBag=null;
					break;
				}
				case CLZNoticeName.DRAW_PAY_BAG_RES:
				{
					if (this._payBag != null)
					{
						this._payBag.drawPayBagres(param1.getBody() as Array);
					}
					break;
				}
				case CLZNoticeName.INIT_PAY_BAG_RES:
				{
					facade.removeCommand(CLZNoticeName.INIT_PAY_BAG_REQ);
					if (this._mcPayBagPanel != null)
					{
						this.sendNotification(CLZNoticeName.HIDE_PAY_BAG_PANEL);
					}
					else
					{
						facade.registerCommand(CLZNoticeName.DRAW_PAY_BAG_REQ, PrizeCommand);
						this._mcPayBagPanel=GameData.getSprite("PayBag");
						Texas.I._mcWindosView.addChildTo(this._mcPayBagPanel);
						Texas.I._mcWindosView.centerXY(this._mcPayBagPanel, 0, -40);
						this._payBag=new PayBagPanel(this._mcPayBagPanel, param1.getBody());
					}
					break;
				}
				case CLZNoticeName.SHOW_BUY_VIP_PANEL_TIP:
				{
					if (this._mcPayPanel != null)
					{
						this.sendNotification(CLZNoticeName.HIDE_BUY_VIP_PANEL_TIP);
					}
					else
					{
						this._mcPayPanel=GameData.getSprite("PayPanelTip");
						this._mcPayPanel["txt1"].text=GameData.tip["PAY_PANEL_TIP_TXT_1"];
						this._mcPayPanel["txt2"].text=GameData.tip["PAY_PANEL_TIP_TXT_2"];
						this._mcPayPanel["txt3"].text=GameData.tip["PAY_PANEL_TIP_TXT_3"];
						CLZButton.setButton(this._mcPayPanel["pay_btn"], GameData.tip["PAY_PANEL_BTN_1"]);
						CLZButton.setButton(this._mcPayPanel["invitation_btn"], GameData.tip["PAY_PANEL_BTN_2"]);
						CLZButton.setButton(this._mcPayPanel["practice_btn"], GameData.tip["PAY_PANEL_BTN_3"]);
						AddBtn.initBtn(this._mcPayPanel, CLZNoticeName.HIDE_BUY_VIP_PANEL_TIP, AddBtn.CLOSE_TWO, "", 4, 4);
						this._mcPayPanel["pay_btn"].addEventListener(MouseEvent.CLICK, this.onPayHandler);
						this._mcPayPanel["invitation_btn"].addEventListener(MouseEvent.CLICK, this.onInvitationHandler);
						this._mcPayPanel["practice_btn"].addEventListener(MouseEvent.CLICK, this.onPracticeHandler);
						Texas.I._mcWindosView.addChildTo(this._mcPayPanel);
						Texas.I._mcWindosView.centerXY(this._mcPayPanel, 0, 0);
					}
					break;
				}
				case CLZNoticeName.HIDE_BUY_VIP_PANEL_TIP:
				{
					this._mcPayPanel["pay_btn"].removeEventListener(MouseEvent.CLICK, this.onPayHandler);
					this._mcPayPanel["invitation_btn"].removeEventListener(MouseEvent.CLICK, this.onInvitationHandler);
					this._mcPayPanel["practice_btn"].removeEventListener(MouseEvent.CLICK, this.onPracticeHandler);
					Texas.I._mcWindosView.removeChildTo(this._mcPayPanel);
					this._mcPayPanel=null;
					break;
				}
				case CLZNoticeName.SHOW_RED:
				{
					facade.registerCommand(CLZNoticeName.WEIBO_REQ, PrizeCommand);
					facade.registerCommand(CLZNoticeName.RED_REQ, PrizeCommand);
					_loc_5=GameData.getSprite("RedBagPanel");
					_loc_6=new RedBagPanel(_loc_5, CLZNoticeName.WEIBO_REQ, CLZNoticeName.HIDE_RED);
					break;
				}
				case CLZNoticeName.HIDE_RED:
				{
					facade.removeCommand(CLZNoticeName.WEIBO_REQ);
					facade.removeCommand(CLZNoticeName.RED_REQ);
					break;
				}
				case CLZNoticeName.SHOW_NATIONAL_DAY:
				{
					facade.registerCommand(CLZNoticeName.NATIONAL_DAY_DRAW_REQ, PrizeCommand);
					_loc_7=GameData.getSprite("NationalDay");
					new NationalDayPanel(_loc_7, param1.getBody() as Array, CLZNoticeName.HIDE_NATIONAL_DAY);
					break;
				}
				case CLZNoticeName.HIDE_NATIONAL_DAY:
				{
					facade.removeCommand(CLZNoticeName.NATIONAL_DAY_DRAW_REQ);
					break;
				}
				default:
				{
					break;
				}
			}
			return;
		}

		private function onPayHandler(event:MouseEvent):void
		{
			this.sendNotification(CLZNoticeName.ON_PAY_VIP);
			return;
		}

		private function onInvitationHandler(event:MouseEvent):void
		{
//			JSFUN.shareInvitationFunc();
			return;
		}

		private function onPracticeHandler(event:MouseEvent):void
		{
			if (GameData._objRoom)
			{
				GameData.IS_ENTER_ROOM=true;
				this.sendNotification(CLZNoticeName.HIDE_BUY_VIP_PANEL_TIP);
				this.sendNotification(CLZNoticeName.OUT_GAME_ROOM, {seatId: this._global.seatId});
			}
			else
			{
				this.sendNotification(CLZNoticeName.HIDE_BUY_VIP_PANEL_TIP);
				this.sendNotification(CLZNoticeName.FAST_ENTER_GAME_REQ);
			}
			return;
		}

		private function windosViewRemove(param1:DisplayObject):void
		{
			if (param1 != null)
			{
			}
			if (Texas.I._mcWindosView.contains(param1))
			{
				Texas.I._mcWindosView.removeChild(param1);
				param1=null;
			}
			return;
		}

		private function showCanawardHandler(param1:int):void
		{
			var onCloseCanawardHandler:Function;
			var onOkCanawardHandler:Function;
			var canaward:*=param1;
			onCloseCanawardHandler=function(event:MouseEvent):void
			{
				facade.sendNotification(CLZNoticeName.HIDE_ACTIVITY_PANEL);
				if (int(_global.userInfo.userVo.icon) == 0)
				{
					facade.sendNotification(CLZNoticeName.SHOW_HELP, HelpMediator.TYPE_0);
				}
				return;
			};
			onOkCanawardHandler=function(event:MouseEvent):void
			{
//				JSFUN.openGameFunc();
				facade.sendNotification(CLZNoticeName.PRIZE_BAG_REWARD_REQ, canaward);
				facade.sendNotification(CLZNoticeName.HIDE_ACTIVITY_PANEL);
				return;
			};
			this._mcCanaward=GameData.getSprite("Activity" + canaward);
			Texas.I._mcWindosView.addChildTo(this._mcCanaward);
			Texas.I._mcWindosView.centerXY(this._mcCanaward);
			this._mcCanaward["close_btn"].visible=false;
			this._mcCanaward["close_btn"].addEventListener(MouseEvent.CLICK, onCloseCanawardHandler);
			this._mcCanaward["ok_btn"].addEventListener(MouseEvent.CLICK, onOkCanawardHandler);
			return;
		}

		private function get mcGameMain():Object
		{
			return viewComponent;
		}

	}
}
